package com.example.zg3_park.RepairOrder

import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.example.lib_base.entity.RepairOrderEntityItem
import com.example.lib_base.net.ApiService

class RepairDataSource(val apiService: ApiService):PagingSource<Int,RepairOrderEntityItem>() {
    override fun getRefreshKey(state: PagingState<Int, RepairOrderEntityItem>): Int? {
        return null
    }

    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, RepairOrderEntityItem> {
        try {
            //当前页码
            val currentPage = params.key ?: 0
            //网络请求
            val repair = apiService.getRepair()
            //下一页
            //val nextPage = if(repair.data.size == 4) currentPage+1 else null
            return LoadResult.Page(repair.data,null,null)
        }catch (e:Exception) {
            return LoadResult.Error(e)
        }
    }
}